package cn.gson.crmdemo.controller.finance;


import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.PaymentPlan;
import cn.gson.crmdemo.model.service.FkjhService;
import cn.gson.crmdemo.model.vo.FkjhVo;

@Controller
public class FkjhController {
	@Autowired
	FkjhService fs;
	public Map<String,Object> yy(JSONArray selecthk,Page page) {
		Map<String, Object> map=new HashMap<String,Object>();
		map.put("list",selecthk);
		map.put("total",page.getTotal());
		return map;
	}
	/*
	 * 
	 * 查询付款计划
	 */
	@RequestMapping("fkjh")
	@ResponseBody
	public Map<String,Object>hk(Integer pageNum,Integer pasgeSize,String fkDate,String gysName,Integer fkState){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selecthk=fs.fkjh(fkDate,gysName,fkState);
		//创建Map集合
	return this.yy(selecthk, page);
}

	/*
	 * 添加付款计划
	 */
	@RequestMapping("addfkjh")
	public String  addfkjh(FkjhVo fo) {
		fs.addfkjh(fo);
		return "redirect:fkjh?pageNum=1&pasgeSize=7";
	}
	/*
	 * 查询采购单
	 */
	
	@RequestMapping("cgd")
	@ResponseBody
	public Map<String,Object>cg(Integer pageNum,Integer pSize){
		//分页
		
		Page<Object> page = PageHelper.startPage(pageNum,pSize);
		//查询数据
		JSONArray selecthk=fs.selectcg();
		//创建Map集合
	return this.yy(selecthk, page);
}
	
	
	/*
	 * 修改付款计划
	 */
	@RequestMapping("xgfkjh")
	public String xgfkjh(FkjhVo fo) {
		fs.xgfkjh(fo);
		return "redirect:fkjh?pageNum=1&pasgeSize=7";
	}
	/*
	 * 修改状态
	 */
	@RequestMapping("xgzt")
	public String xgzt(int a,int b,int o) {
		fs.xgzt(a,b,o);
		return "redirect:fkjh?pageNum=1&pasgeSize=7";
	}
	
	
	//是否付款
	@RequestMapping("fkjh-sffk")
	@ResponseBody
	public Map<String,Object>selectfk(Integer pageNum,Integer pasgeSize,Integer p){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selecthk=fs.selectfk(p);
		//创建Map集合
	return 	this.yy(selecthk, page);
}
	
	//根据供应商查询
	@RequestMapping("fkjh-gyscx")
	@ResponseBody
	public Map<String,Object>selectfk(Integer pageNum,Integer pasgeSize,String  gys1){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selecthk=fs.selectgys("%"+gys1+"%");
		//创建Map集合
			return 	this.yy(selecthk, page);
}
	
}
